package com.common.base.tools.utils

import androidx.annotation.IdRes
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentTransaction

/**
 * 三疯
 * *************************
 *
 * *************************
 */
object FragmentUtils {
    var containerViewId: Int? = null
    var fragmentActivity: FragmentActivity? = null
    fun start(
        fragment: Fragment,
        @IdRes containerViewId: Int,
        fragmentActivity: FragmentActivity
    ) {
        FragmentUtils.containerViewId = containerViewId
        FragmentUtils.fragmentActivity = fragmentActivity

        val fragmentTransaction: FragmentTransaction =
            fragmentActivity.supportFragmentManager.beginTransaction()
                .replace(containerViewId, fragment)
        fragmentTransaction.commit()
    }

    fun start(
        fragment: Fragment,
    ) {
        if (containerViewId != null && fragmentActivity != null) {
            val fragmentTransaction: FragmentTransaction =
                fragmentActivity!!.supportFragmentManager.beginTransaction()
                    .replace(containerViewId!!, fragment)
            fragmentTransaction.commit()
        }

    }
}